const express = require('express');
const router = express.Router();
const { getToken } = require('../token/token');
const path = require('path');
const fs = require('fs');
router.get('/', (req, res) => {
    const tokenResult = getToken(req.headers.authorization);
    if (!tokenResult.boolean) {
        return res.status(405).send(tokenResult.msg);
    }
    const menusListPath = path.join(__dirname, '../src/Menus/menusList.json');
    fs.promises.readFile(menusListPath, 'utf8')
        .then((data) => {
            const menus = JSON.parse(data);
            const msg = getToken(req.headers.authorization).msg;
            return res.status(200).json({ msg, menus });
        })
        .catch((err) => {
            console.error('读取文件错误:', err);
            return res.status(500).json({ error: '服务器错误' });
        });
});
module.exports = router;
